﻿using UnityEngine;
using System.Collections;
using LitJson;

public class MapEdit : MonoBehaviour
{
    void Start()
    {
        var mapJson = new JsonData();
        var enemys = GameObject.FindGameObjectsWithTag("Enemy");
        var i = 1;
        foreach (var tob in enemys)
        {
            var enemyJson = new JsonData();
            enemyJson["type"] = "Enemy";
            enemyJson["id"] = i;
            enemyJson["pos"] = tob.transform.position.ToJsonData();
            enemyJson["scale"] = tob.transform.localScale.ToJsonData();
            enemyJson["rotation"] = tob.transform.rotation.eulerAngles.ToJsonData();
            var enemyAI = tob.GetComponentInChildren<EnemyAI>();
            enemyJson["EnemyAI"] = new JsonData();
            enemyJson["EnemyAI"]["speed"] = enemyAI.speed;
            enemyJson["EnemyAI"]["pathPoses"] = enemyAI.pathPoses.ToJsonData();
            var enemySight = tob.GetComponentInChildren<EnemySight>();
            enemyJson["EnemySight"] = new JsonData();
            enemyJson["EnemySight"]["sightAngle"] = enemySight.sightAngle;
            enemyJson["EnemySight"]["stepDegree"] = enemySight.stepDegree;
            enemyJson["EnemySight"]["sightDistance"] = enemySight.sightDistance;
            mapJson.Add(enemyJson);
            i++;
        }
        var walls = GameObject.FindGameObjectsWithTag("Wall");
        i = 1;
        foreach (var tob in walls)
        {
            var wallJson = new JsonData();
            wallJson["type"] = "Wall";
            wallJson["id"] = i;
            wallJson["pos"] = tob.transform.position.ToJsonData();
            wallJson["scale"] = tob.transform.localScale.ToJsonData();
            wallJson["rotation"] = tob.transform.rotation.eulerAngles.ToJsonData();
            mapJson.Add(wallJson);
            i++;
        }
    }
}
